package com.biyabi.controller;

import com.biyabi.entity.Brand;
import com.biyabi.pojo.BrandsData;
import com.biyabi.pojo.Result;
import com.biyabi.service.BrandService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/back/brand")
public class BrandController {
    @Resource
    private BrandService brandService;
    @RequestMapping("/findAll")
    public BrandsData findAll(Integer page, Integer rows,String columnName,String columnValue){
        return brandService.findAll(page,rows,columnName,columnValue);
    }
    @RequestMapping("/findAllBrand")
    public List<Brand> findAllBrand(){
        return brandService.findAllBrand();
    }
    @RequestMapping("/add")
    public Result add(Brand brand){
        Result result = new Result();
        try{
            brandService.add(brand);
            result.setStatus(true);
            result.setMessage("添加品牌成功！");
        }catch(Exception e){
            result.setStatus(false);
            result.setMessage("添加品牌失败！");
        }
        return result;
    }
    @RequestMapping("/update")
    public Result update(Brand brand){
        Result result = new Result();
        try{
            brandService.update(brand);
            result.setStatus(true);
            result.setMessage("更新品牌成功！");
        }catch(Exception e){
            result.setStatus(false);
            result.setMessage("更新品牌失败！");
        }
        return result;
    }
    @RequestMapping("/findOne")
    public Brand findOne(String id){
        return brandService.findOne(id);
    }

}
